@extends('manage.layout')

@section('content')
    <section class="content-header">
        <h1>
            附件管理
            <small>Preview</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
            <li><a href="#">Case</a></li>
            <li class="active">Case Attachment</li>
        </ol>
    </section>

    <section class="content">
        <div class="row">
            <!-- left column -->
            <div class="col-md-12">
                <!-- general form elements -->
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h3 class="box-title">上传附件</h3>
                    </div>
                    <form action="{{ url('case/annex') }}" method="post" role="form" style="max-width: 800px;" enctype="multipart/form-data" id="annex_form" onsubmit="return uploader()">
                        {{csrf_field()}}
                        <input type="hidden" id="annex_id" name="annex_id" value="{{ $case->id }}">
                        <div class="box-body" style="width: 800px;">

                            <div class="form-group">
                                <label for="exampleInputEmail1">权重</label>
                                <input type="number" id="annex_rank" name="rank" class="form-control" min="0" placeholder="rank" value="0">
                                {{--<input type="number" id="picture_rank" name="rank" class="form-control" min="0" placeholder="rank" value="0">--}}
                            </div>

                            <span id="attachment" style="display: none">case/attachment/</span>
                            <span id="picture" style="display: none">case/picture/</span>
                            <div class="form-group">
                                <label for="exampleInputPassword1">附件</label>
                                <div id="containerg">
                                    <a id="selectfilesg" href="javascript:void(0);" class='btn btn-primary'>选择文件</a>
                                    {{--<a id="postfiles" href="javascript:void(0);" class='btn btn-primary'>开始上传</a>--}}
                                </div>
                                <div class='clear container'>
                                    <!--<div id="dd" class="row"></div>-->
                                    <div id="ossfileg"></div>
                                </div>
                                <div class='clear container' style="display: none;">
                                    <div id="img"></div>
                                </div>
                                <input type="hidden" name="path" value="" id="getpathg">
                            </div>
                            <div class="box-footer">
                                <button type="submit" class="btn btn-primary">提交</button>
                            </div>
                            {{--<pre id="console"></pre>--}}

                        </div>
                        <!-- /.box-body -->

                    </form>
                    <!-- /.box-header -->
                    <!-- form start -->

                </div>
                <div class="box box-info">
                    <div class="box-header with-border">
                        <h3 class="box-title">附件</h3>
                    </div>
                    <div class="box-body">
                        @if(empty($annex))还未添加附件
                        @else
                            @foreach($annex as $a)
                                <div style="margin: 10px;margin-top: 20px;width: 150px;float: left;text-align: center;padding: 5px;">
                                    {{--<img src="{{ $a['path'] }}" width="100px" height="100px">--}}
                                    <div style="width: 100px;height: 100px"><a href="http://vipyipoint.oss-cn-beijing.aliyuncs.com/{{ $a['path'] }}">{{ $a['name'] }}</a></div>

                                    {{--<a href="javascript:delannex('{{ $a['id'] }}','{{ $a['name'] }}')"><div class="fa fa-fw fa-remove" style="background-color:#fff;display:inline-block;width: 18px;height: 18px;border:1px solid #3c8dbc;border-radius: 9px;position: relative;top: -48px;right: 12px;z-index: 666;"></div></a><br />--}}
                                    {{--<p>{{ $a['brief'] }}</p>--}}
                                    <br />
                                    @if($a['status'] == 1)
                                        <a href="javascript:annexStatus('{{ $a['id'] }}',0)" class='btn btn-warning btn-xs'>禁用</a>
                                    @else
                                        <a href="javascript:annexStatus('{{ $a['id'] }}',1)" class='btn btn-success btn-xs'>启用</a>
                                    @endif
                                    <a href="javascript:delannex('{{ $a['id'] }}','{{ $a['path'] }}')" class='btn btn-danger btn-xs'>删除</a>
                                </div>

                            @endforeach
                        @endif
                    </div>

                </div>
            </div>
        </div>
    </section>
@stop
@section('script')
    <script type="text/javascript" src="/oss/upload_att.js"></script>
    <script>
        //上传附件
        $(function() {
            $("form").submit(function(event) {
                event.preventDefault();
                var url = $(this).attr("action");
                var data = $("form").serialize();
                $.ajax({
                    url: url,
                    type: "POST",
                    data: data,
                    dataType: "json",
                    success: function(res) {
                        console.log(res);
                        if(res.code == 100) {
//                            window.location.href = "/caseList";
                            location.reload();
                            layer.msg(res.msg)
                        }
                        else {
                            layer.msg(res.msg)
                        }
                    }
                });
            });
        });

        //删除附件
        function delannex(id,path) {
            layer.confirm('删除后不可恢复，是否继续?', {
                btn:['确定','取消']
            },function() {
                $.ajax({
                    url: '/case/deleteAnnex',
                    type: "GET",
                    data: {id:id,path:path},
                    dataType: "json",
                    success: function(data) {
                        console.log(data);
                        if(data.code == 100) {
                            window.location.href = window.location.href;
                            layer.msg(data.msg)
                        }
                        else {
                            layer.msg(data.msg)
                        }
                    }
                });
            },function() {

            });
        }

        //禁用,启用
        function annexStatus(id,status) {
            $.ajax({
                url: '/case/annexStatus',
                type: "GET",
                data: {id:id,status:status},
                dataType: "json",
                success: function(res) {
                    console.log(res);
                    if(res.code == 100) {
                        window.location.href=window.location.href;
                        layer.msg(res.msg, {time:1500, icon:6})
                    }
                    else {
                        layer.msg(res.msg, {time:1500, icon:5})
                    }
                }
            });
        }
    </script>
@stop
